(function () {
    var init, global, initFileInputs, bind, msg;

    global = this;

    init = function () {
        var formsElements, i;
        msg = global.document.createElement('div');
        msg.innerHTML = '<strong>Nahrávám obrázky...</strong><br />' +
                '(U větších obrázků to může trvat až několik minut)';
        msg.style.position = 'fixed';
        msg.style.border = 'solid 1px #fe8d24';
        msg.style.background = '#efefef';
        msg.style.padding = '15px';
        msg.style.width = '350px';
        msg.style.textAlign = 'center';
        msg.style.top = ((global.window.innerWidth !== undefined ?
                global.window.innerHeight + global.window.pageYOffset :
                global.document.body.clientHeight +
                global.document.body.scrollLeft) / 2 - 100) + 'px';
        msg.style.left = ((global.window.innerWidth !== undefined ?
                global.window.innerWidth + global.window.pageXOffset :
                global.document.body.clientWidth +
                global.document.body.scrollTop) / 2 - 175) + 'px';
        msg.style.display = 'none';
        global.document.getElementById('content').appendChild(msg);
        formsElements = global.document.getElementsByTagName('form');
        for (i = formsElements.length - 1; i >= 0; i -= 1) {
            initFileInputs(formsElements[i]);
        }
    };

    initFileInputs = function (form) {
        var inputs, i, hasFiles, input;
        inputs = form.getElementsByTagName('input');
        hasFiles = false;
        for (i = inputs.length - 1; i >= 0; i -= 1) {
            input = inputs[i];
            if (input.type.toLowerCase() === 'file') {
                hasFiles = true;
                bind(input, 'change', function () {
                    form.setImages = true;
                });
            }
        }
        if (hasFiles) {
            form.setImages = false;
            bind(form, 'submit', function (e) {
                if (form.setImages) {
                    msg.style.display = '';
                }
            });
        }
    };

    bind = function (element, event, handler) {
        if (element.addEventListener instanceof Function) {
            element.addEventListener(event, handler, false);
        } else {
            element.attachEvent('on' + event, handler);
        }
    };

    if (this.addEventListener instanceof Function) {
        this.addEventListener('DOMContentLoaded', init, false);
    } else {
        this.attachEvent('onload', init);
    }
}());